class SchoolsController < ApplicationController

  before_filter :login_required

  def index
    @schools = current_user.schools
  end

  def new
    @school = School.new
  end

  def edit
    @school = current_user.schools.find(params[:id])
  end

  def create
    @school = School.new(params[:school])
    @school.user = current_user
    respond_to do |format|
      if @school.save
        flash[:notice] = 'School was successfully created.'
        format.html { redirect_to schools_url }
      else
        format.html { render :action => "new" }
      end
    end
  end

  def update
    @school = current_user.schools.find(params[:id])

    respond_to do |format|
      if @school.update_attributes(params[:school])
        flash[:notice] = 'School was successfully updated.'
        format.html { redirect_to schools_url }
      else
        format.html { render :action => "edit" }
      end
    end
  end

  def destroy
    @school = current_user.schools.find(params[:id])
    @school.destroy

    respond_to do |format|
      format.html { redirect_to schools_url }
    end
  end
end
